﻿/***********************************************************************
 * <copyright file="SqlServerPermissionInSiteDao.cs" company="B/S JSC">
 * -->    Copyright (C) statement. All right reserved
 * </copyright>
 * 
 * Created:   Hoang Bich Son 
 * Email:    sonhb@newman.vn
 * Website:
 * Create Date: Saturday, March 29, 2014
 * Usage: 
 * 
 * RevisionHistory: 
 * Date         Author               Description 
 * 
 * ************************************************************************/

using System;
using System.Collections.Generic;
using System.Data;
using BusinessSecurity;
using DataObjects;
using DataObjects.ADO;
using DataSecurity.ADO.SqlServer.DataContext;
using DataSecurity.StandartInterfaces;

namespace DataSecurity.ADO.SqlServer.Dictionary
{
    /// <summary>
    /// SqlServerPermissionInSiteInSite
    /// </summary>
    public class SqlServerPermissionInSiteDao : IPermissionInSite
    {
        /// <summary>
        /// Gets the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public PermissionInSite Get(int id)
        {
            const string sql = @"uspGet_PermissionInSite_ByID";
            object[] parms = { "@PermissionId", id };
            return Db.Read(sql, CommandType.StoredProcedure, Make, parms);
        }

        /// <summary>
        /// Gets the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public PermissionInSite Get(string name)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets the list.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public List<PermissionInSite> GetPermissionInSiteByPermissionId(int id)
        {
            const string sql = @"uspPermissionInSite_GetByPermissionID";
            object[] parms = { "@PermissionId", id };
            return Db.ReadList(sql, CommandType.StoredProcedure, Make, parms);
        }

        /// <summary>
        /// Gets the permission in site by site identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public List<PermissionInSite> GetPermissionInSiteBySiteId(int id)
        {
            const string sql = @"uspPermissionInSite_GetBySiteID";
            object[] parms = { "@SiteId", id };
            return Db.ReadList(sql, CommandType.StoredProcedure, Make, parms);
        }

        /// <summary>
        /// Gets the permission in site by identifier.
        /// </summary>
        /// <param name="permissionId">The permission identifier.</param>
        /// <param name="siteId">The site identifier.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public List<PermissionInSite> GetPermissionInSiteById(int permissionId, int siteId)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets the list.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public List<PermissionInSite> GetList()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets the paged.
        /// </summary>
        /// <param name="currentPage">The current page.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public List<PermissionInSite> GetPaged(int currentPage)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets the size of the page.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public int GetPageSize()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Inserts the specified permission.
        /// </summary>
        /// <param name="permissionInSites">The permission in sites.</param>
        /// <returns></returns>
        public object Insert(List<PermissionInSite> permissionInSites)
        {
            const string sql = @"uspPermissionInSite_Insert";
            return Db.Insert(sql, CommandType.StoredProcedure, Take(permissionInSites));
        }

        /// <summary>
        /// Updates the specified PermissionInSite.
        /// </summary>
        /// <param name="permissionInSite">The permission in site.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public object Update(PermissionInSite permissionInSite)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Deletes the specified PermissionInSite.
        /// </summary>
        /// <param name="permissionId">The permission identifier.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public object Delete(int permissionId)
        {
            const string sql = @"uspPermissionInSite_DeleteByPermissionID";
            object[] param = { "@PermissionId", permissionId };
            return Db.Delete(sql, CommandType.StoredProcedure, param);
        }

        /// <summary>
        /// The make
        /// </summary>
        private static readonly Func<IDataReader, PermissionInSite> Make = reader =>
          new PermissionInSite
          {
              SiteId = reader["SiteId"].AsId(),
              PermissionId = reader["PermissionId"].AsId()
          };

        /// <summary>
        /// Takes the specified items.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <returns></returns>
        private static object[] Take(List<PermissionInSite> items)
        {
            return new object[]  
            {
                "@PermissionInSite", Mapper.ToDataContext(items).ToDataTable()
            };
        }
    }
}
